import React from 'react';
import {connect} from 'react-redux'
import {loadMenus} from "../../redux/menu/menu.redux";

@connect(state => state.menu, {loadMenus})
class authButton extends React.Component {
    constructor(props) {
        super(props);
    }

    recursiveCloneChildren(children) {
        return React.Children.map(children, (child) => {
            if (!React.isValidElement(child)) return child;
            const props = { ...{ className: '' }, ...child.props };
            let childProps = {};
            if (React.isValidElement(child) && props['data-auth']) {
                // console.log(props['data-auth']);
                if(!this.props.button.some((item) => {return item==props['data-auth']})){
                    // console.log('child',child)
                    childProps = {
                        'data-auth':999999
                    };
                }else{
                    // console.log('child',child)
                    childProps = {
                        'data-auth':null
                    };
                }
            }
            childProps.children = this.recursiveCloneChildren(child.props.children);
            return React.cloneElement(child, childProps);
        });
    }

    render(){
        return this.recursiveCloneChildren(this.props.children)
    }
}
export default authButton